package com.yu.tool;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Random;

/**
 * 验证码生成器
 */
public class Validate {
	public int width = 60;
	public int height = 20;
	public String getCode() {
		Random rnd = new Random();
		int random = rnd.nextInt(8999)+1000;
		String randStr = String.valueOf(random);
		return randStr;
	}
	public BufferedImage getImage(String randStr) {
		BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
		Graphics g = image.getGraphics();
		g.setColor(new Color(200,200,200));
		g.fillRect(0, 0, width, height);//����ɫ
		
		
		g.setColor(Color.black);//��ʾ��ͼ����
		g.setFont(new Font("",Font.PLAIN,20));
		g.drawString(randStr,10,17);
		
		for(int i = 0;i<100;i++){//100���ŵ�
			Random rnd = new Random();
			int x = rnd.nextInt(width);
			int y = rnd.nextInt(height);
			g.drawOval(x, y, 1, 1);
		}
		return image;
	}	
}
